
use "$data_input/identified/BancoJulgados_AKM.dta", clear

******************************************************************************
********** *Figure A6: Histogram of duration of cases in days ****************
******************************************************************************

summ duration_main,d
histogram duration_main, width(100) frac graphregion(color(white)) ///
note( N = `r(N)' cases) fcolor(dknavy) lcolor(black) lw(medthin) ///
ylab(, nogrid) xlabel(0(1000)5500) xtitle("Case duration (days)") ///
xline(`r(p10)', lp(dash)) xline(`r(p90)', lp(dot))
graph export "$paper_figures\hist_SP_duration.pdf", replace 

******************************************************************************
********* Table A10: Case composition and entrance exam performance  *********
******************************************************************************

use "$data_input/identified/BancoJulgados_AKM.dta", clear

gcollapse (mean) case_type_* (count) n_cases = case_type, by(Judge_idP Court_idP2 month)

merge m:1 Judge_idP using "$temp/judges_level_rank.dta"

bys Judge_idP: egen quintile_all = max(quintile)

eststo drop *
forv i = 1/8 {

	eststo: reghdfe case_type_`i' ib5.quintile_all , a(Court_idP2 Concurso_enc month) vce(cluster Judge_idP)
	qui summ case_type_`i'  if e(sample)==1
	loc mean: di %6.2fc `r(mean)'
	estadd loc mean `mean'
}

esttab using "$paper_tables/regs_SP_balance_casetype_month.tex", drop(_cons 5.quintile_all) booktabs f replace ///
stats(N mean r2, fmt(%9.0gc %9.2fc %9.2fc) ///
labels(Observations "Dep var mean" R-Squared)) label se ///
coeflabels(1.quintile_all "Top quintile" 2.quintile_all "4th quintile"  3.quintile_all "3rd quintile"  ///
	4.quintile_all "2nd quintile") r2 nostar ///
	mtitles("Common Civil" "Small causes" "\shortstack{Debt \\ enforcement}" "\shortstack{Extrajudicial \\ enforcement}"  "\shortstack{Sentence \\ enforcement}" ///
	"Criminal" "Embargoes" "Other cases")


